import { _decorator, Component, Node, assetManager, AudioClip, AudioSource, find, loader, resources } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('audio')
export class audio extends Component {
	@property(AudioClip)
	public clip: AudioClip = null!;   
	@property(AudioSource)
	public audioSource: AudioSource = null!;
	start() {
		/*
		// 依赖组件
		let player = this.getComponent(AudioSource)
		// let btnNode = find('BUTTON_NODE_NAME');
		// btnNode!.on(Node.EventType.TOUCH_START, this.playAudio, this);
		resources.load('misc/music',AudioClip,(err,clip)=>{
			player.clip = clip
			player.play()
			// player.playing()
			// player.pause()
			// player.stop()
			// player.loop()
			// player.volume=1
		})
		*/
		// 一次性，不依赖组件
		resources.load('misc/music', AudioClip, (err, clip) => {
			let player = this.getComponent(AudioSource)
			player.playOneShot(clip,1)
		})
	}
	// playAudio() {
	// 	this.audioSource.play();
	// }
}

